﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL.ComplexClasses;
using DAL;
using App_Log;
using App_Utils;


namespace BLL
{
    public class BL_AdditionalInfo
    {
        public static AdditionalInfo SaveRecord(AdditionalInfo objAdditionalInfo)
        {
            try
            {
                clsLog.logMsg("AdditionalInfo", "SaveRecord", "Started");
                DAL.ithubEntities db = new ithubEntities();
                var query = (from q in db.tblAdditionalInfoes where q.info_id == objAdditionalInfo.info_id select q).SingleOrDefault();

                if (query != null)
                {
                    query = (tblAdditionalInfo)clsUtils.ConvertToObject(objAdditionalInfo, new tblAdditionalInfo());
                    db.SaveChanges();
                }
                else
                {
                    tblAdditionalInfo _objtblAdditionalInfo = new tblAdditionalInfo();
                    _objtblAdditionalInfo = (tblAdditionalInfo)clsUtils.ConvertToObject(objAdditionalInfo, new tblAdditionalInfo());
                    db.tblAdditionalInfoes.Add(_objtblAdditionalInfo);
                    db.SaveChanges();
                    objAdditionalInfo = (AdditionalInfo)clsUtils.ConvertToObject(_objtblAdditionalInfo, objAdditionalInfo);
                    
                }
            }
            catch (Exception ex)
            {
                clsLog.logError("AdditionalInfo", "SaveRecord", ex.Message);
            }
            return objAdditionalInfo;
        }

        public static List<AdditionalInfo> GetAdditionalInfos(long id, string module)
        {
            List<AdditionalInfo> objAdditionalInfo = new List<AdditionalInfo>();
            
            try
            {
                clsLog.logMsg("AdditionalInfo", "GetAdditionalInfos", "Started");

                DAL.ithubEntities db = new ithubEntities();
                var query = (from q in db.tblAdditionalInfoes where q.is_visible == true select q);


                List<tblAdditionalInfo> _objAdditionalInfo = query.ToList();
                foreach (tblAdditionalInfo item in _objAdditionalInfo)
                {
                    objAdditionalInfo.Add((AdditionalInfo)App_Utils.clsUtils.ConvertToObject(item, new AdditionalInfo()));
                }
            }
            catch (Exception ex)
            {
                clsLog.logError("User", "GetAdditionalInfos", ex.Message);
            }
            return objAdditionalInfo;
        }
    }
}
